package training_camp.day5.leetcode349;

import java.util.ArrayList;
import java.util.HashSet;

class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> set = new HashSet<>();
        for (int i : nums1) {
            set.add(i);
        }
        ArrayList<Integer> list = new ArrayList<>();
        for (int i : nums2) {
            if (set.contains(i)){
                list.add(i);
                set.remove(i);
            }
        }
        return list.stream().mapToInt(value -> value).toArray();
    }
}